//
//  TYMBBleRefreshView.m
//  TY_MotorRemoteControl
//
//  Created by 徐伟新 on 2023/11/16.
//  Copyright © 2023 zhongdaodianzi. All rights reserved.
//

#import "TYMBBleRefreshView.h"

@interface TYMBBleRefreshView ()
@property (nonatomic, strong) UIImageView *bgImgV;
@property (nonatomic, strong) UIImageView *refreshImgV;
@property (nonatomic, strong) CABasicAnimation *animationLayer;
@end

@implementation TYMBBleRefreshView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [BLE_MAN startScanAction];
}

- (void)layoutSubviews {
    
    self.bgImgV.frame = self.bounds;
//    self.refreshImgV.center = CGPointMake(self.width/2.0, self.height/2.0);
}

- (CABasicAnimation *)animationLayer {
    if (!_animationLayer) {
        _animationLayer = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        _animationLayer.toValue = @(2*M_PI);
        _animationLayer.duration = 1;
        _animationLayer.removedOnCompletion = false;
        _animationLayer.repeatCount = MAXFLOAT;
    }
    return _animationLayer;
}


- (void)setIsStart:(BOOL)isStart {
    _isStart = isStart;
    if (isStart) {
        [self.layer removeAllAnimations];
        [self.layer addAnimation:self.animationLayer forKey:nil];
    }else {
        [self.layer removeAllAnimations];
    }
}


- (UIImageView *)bgImgV {
    if (!_bgImgV) {
        _bgImgV = [[UIImageView alloc]initWithFrame:self.bounds];
        _bgImgV.image = [UIImage imageNamed:@"TY-重新扫描整"];
        [self addSubview:_bgImgV];
    }
    return _bgImgV;
}

- (UIImageView *)refreshImgV {
    if (!_refreshImgV) {
        _refreshImgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 21.5, 24)];
        _refreshImgV.image = [UIImage imageNamed:@"TY-重新扫描"];
        [self insertSubview:_refreshImgV aboveSubview:self.bgImgV];
    }
    return _refreshImgV;
}

@end
